﻿
//****************
//Cookie Functions
//****************



function createCookie(name,value,days) {
  value = escape(value); //in case of semi colons
  var expires;
  if (days) {
    var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function toJson(o) {
  var ojson = '{';
  var delim = '';
  for (var property in o) {
    ojson += delim;
    ojson += "'" + property + "': ";
    if (isNaN(o[property])) {
      if (o[property] == "[object Object]") {
        ojson += toJson(o[property]);
      } else {
        ojson += "'" + o[property] + "'";
      }
    } else {
      ojson += o[property];
    }
    delim = ', ';
  }
  return ojson + '}';;
}

function toHtml(o) {
  var ohtml = '{';
  var delim = '';
  for (var property in o) {
    ohtml += delim;
    ohtml += "'" + property + "': ";
    if (isNaN(o[property])) {
      if (o[property] == "[object Object]") {
        ohtml += toHtml(o[property]);
      } else {
        ohtml += "'" + o[property] + "'";
      }
    } else {
      ohtml += o[property];
    }
    delim = ', ';
  }
  return ohtml + '}';;
}
function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

function guid() {
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}